﻿using System;
using Artech.PetShop.Common;
using Artech.PetShop.Orders.BusinessEntity;
using Artech.PetShop.Products.Interface;
using Artech.PetShop.Products.Service.Interface;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;

namespace Artech.PetShop.Products
{
    [CachingCallHandler(0,30,0)]
    public class ProductService : IProduct
    {
        private IProductService _proxy = ServiceProxyFactory.Create<IProductService>("productservice");

        #region IProduct Members
        [CachingCallHandler(0,30,0)]
        public Product GetProduct(Guid productID)
        {
            Product product = this._proxy.GetProductByID(productID);
            if (product == null)
            { 
                throw new BusinessException(string.Format("The product whose ID is \"{0}\" does not exist.", productID));
            }

            return product;
        }

        #endregion
    }
}